//
//  CollectViewController.m
//  hellomui
//
//  Created by apple on 15/11/18.
//  Copyright © 2015年 zt.td. All rights reserved.
//

#import "CollectViewController.h"
#import "DDifficultViewController.h"
#import "LoginAndRegistViewController.h"
@interface CollectViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *web;
//@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *loading;

@end

@implementation CollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    _loading.hidden = NO;

    

    self.title = @"我的收藏";
    // Do any additional setup after loading the view from its nib.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSString *userid = [NSString stringWithFormat:@"%@", NSUSER_DEF(@"USERID")];
    self.web.delegate = self;
    
   NSString *path = [@"http://182.92.117.144:8080/study-manager/collection?userid=" stringByAppendingString:userid];
    
    [_web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:path]]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


 -(void)testLV:(NSString *)str{
        if (!NSUSER_DEF(@"USERID")) {
            LoginAndRegistViewController *login = [self.storyboard instantiateViewControllerWithIdentifier:@"loginAndRegist"];
            [self presentViewController:login animated:NO completion:nil];
            
        }else{
            DDifficultViewController *difi = [[DDifficultViewController alloc]initWithNibName:@"DDifficultViewController" bundle:nil];
            
            difi.idValue = str;
            //    [self presentViewController:difi animated:YES completion:nil];
            [difi setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:difi animated:YES];
            
        }
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
      BOOL bools = YES;

    NSLog(@"%@",[NSString stringWithFormat:@"%@",request]);
    
     NSString *str = [NSString stringWithFormat:@"%@",request];
    
    if ([str rangeOfString:@"videoId=" options:NSRegularExpressionSearch].location != NSNotFound){
        
        NSArray *array = [str componentsSeparatedByString:@"videoId="];
        NSString *value = [NSString stringWithFormat:@"%@", [array[1] componentsSeparatedByString:@" }"][0]];
        bools = NO;
        [self testLV:value];
    }
    
    
    return YES;
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
//     _loading.hidden = NO;
//    [_loading setCenter:CGPointMake(MAIN_WIDTH/2+30,MAIN_HEIGHT/2)];
//_loading.backgroundColor = [UIColor grayColor];
//[_loading setTintColor:[UIColor grayColor]];
//_loading.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
//[self.view addSubview:_loading];
//[_loading startAnimating];
//    [[MBProgressController sharedInstance]showWithText:@"正在加载"];
    [[MBProgressController sharedInstance] showTipsLoadingWithText:@"正在加载" AndDelay:3];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    self.navigationItem.title=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];//获取当前页面的title
//    [_loading stopAnimating];
//    _loading.hidden = YES;
//    [[MBProgressController sharedInstance]hide];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
